﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WickedFlame.Util;
using WickedFlame.Util.Controls;
using WickedFlame.VecDraw.Plugins;

namespace WickedFlame.VecDraw.Views
{
    /// <summary>
    /// Interaction logic for PluginPanelView.xaml
    /// </summary>
    public partial class PluginPanelView : UserControl
    {
        static object syncRoot = new object();

        public PluginPanelView()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(PluginPanelView_Loaded);
            this.CommandBindings.Add(new CommandBinding(ExpandCommand, this.OnExecuteCommand, this.OnCanExecuteCommand));
        }

        void PluginPanelView_Loaded(object sender, RoutedEventArgs e)
        {
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        public bool IsExpanded
        {
            get
            {
                return (bool)GetValue(IsExpandedProperty);
            }
            set
            {
                SetValue(IsExpandedProperty, value);
            }
        }

        public static readonly DependencyProperty IsExpandedProperty =
            DependencyProperty.Register("IsExpanded", typeof(bool), typeof(PluginPanelView), new PropertyMetadata(true));

        private static RoutedUICommand expandCommand = null;
        public static RoutedUICommand ExpandCommand
        {
            get
            {
                lock (syncRoot)
                {
                    if (null == expandCommand)
                    {
                        expandCommand = new RoutedUICommand("ExpandCommand", "ExpandCommand", typeof(PluginPanelView));
                    }
                }
                return expandCommand;
            }
        }

        internal virtual void OnExecuteCommand(object sender, ExecutedRoutedEventArgs e)
        {
            if (!e.Handled && e.Command == ExpandCommand)
            {
                if (IsExpanded)
                    IsExpanded = false;
                else
                    IsExpanded = true;

                e.Handled = true;
            }
        }

        protected virtual void OnCanExecuteCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
    }
}
